package com.magina.antiPro.response;

import java.util.HashMap;
import java.util.Map;

public class RequestContextProxy {
    public static transient ThreadLocal<Map<String, String>> threadLocal = new ThreadLocal();

    public RequestContextProxy() {
    }

    public static Map<String, String> getContextMap() {
        Map<String, String> map = (Map)threadLocal.get();
        return map;
    }

    public static void setContextMap(Map<String, String> contextMap) {
        threadLocal.set(contextMap);
    }

    public static String getRequestUsername() {
        Map<String, String> contextMap = getContextMap();
        return contextMap == null ? null : (String)contextMap.get("currentUserName");
    }

    public static String getRequestUserId() {
        Map<String, String> contextMap = getContextMap();
        return contextMap == null ? null : (String)contextMap.get("currentUserId");
    }

    public static String getRequestUserNickName() {
        Map<String, String> contextMap = getContextMap();
        return contextMap == null ? null : (String)contextMap.get("currentUserId");
    }

    public static String getRequestExtensionId() {
        Map<String, String> contextMap = getContextMap();
        return contextMap == null ? null : (String)contextMap.get("currentUserExtensionId");
    }

    public static String get(String key) {
        Map<String, String> contextMap = getContextMap();
        return contextMap == null ? null : (String)contextMap.get(key);
    }

    public static String putRequestUsername(String value) {
        return put("currentUserName", value);
    }

    public static String put(String key, String value) {
        Map<String, String> contextMap = getContextMap();
        if (contextMap == null) {
            contextMap = new HashMap();
            setContextMap((Map)contextMap);
        }

        return (String)((Map)contextMap).put(key, value);
    }

    public static void clear() {
        threadLocal.remove();
    }

    public static String getToken() {
        Object value = get("currentUserToken");
        return null != value ? value.toString() : "";
    }

    public static void setToken(String token) {
        put("currentUserToken", token);
    }

    public static void setNickName(String nickName) {
        put("currentUser", nickName);
    }

    public static void setUserID(String userID) {
        put("currentUserId", userID);
    }

    public static void setUsername(String username) {
        put("currentUserName", username);
    }

    public static void setExtensionId(String extensionId) {
        put("currentUserExtensionId", extensionId);
    }
}
